﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DAL;
using System.Data;
namespace FubiManger.UI
{
    partial class EditsendAddrForm : Smobiler.Core.Controls.MobileForm
    {
        public EditsendAddrForm() : base()
        {
            //This call is required by the SmobilerForm.
            InitializeComponent();
        }
        /// <summary>
        /// 商户ID
        /// </summary>
        public string mercahntid { get; set; }
        /// <summary>
        /// 配送地址集合
        /// </summary>
        List<ms_merchant_address> addrlist = new List<ms_merchant_address>();
        private void panclose_Press(object sender, EventArgs e)
        {
            this.Close();
        }

        private void panaddr_Press(object sender, EventArgs e)
        {
            gps1.GetGps();
        }

        private void pansave_Press(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtaddr.Text))
            {
                MessageBox.Show("请填写配送地址");
            }
            else if (string.IsNullOrEmpty(Longitude))
            {
                MessageBox.Show("请获取GPS坐标");

            }
            else
            {
                merchant_addressDal.Addaddr(txtaddr.Text, Longitude, Latitude, mercahntid);
                txtaddr.Text = "";
                Longitude = "";
                Latitude = "";
                MessageBox.Show("配送地址创建成功");
                Getdate();

            }
        }
        string Longitude ="";
        string Latitude = "";
        private void gps1_GotLocation(object sender, GPSResultArgs e)
        {
            if (e.isError == false)
            {
                GPSResultArgs gps = e.ToGCJ02();
                Longitude = gps.Longitude.ToString();//经度
                Latitude = gps.Latitude.ToString();//纬度
                txtaddr.Text = gps.Location;//当前位置
            }
        }

        private void EditsendAddrForm_Load(object sender, EventArgs e)
        {
            Getdate();

        }
        /// <summary>
        /// 获取数据
        /// </summary>
        public void Getdate()
        {
            lvaddr.Rows.Clear();
            addrlist = merchant_addressDal.Querybyid(mercahntid);
            DataTable table = new DataTable();
            table.Columns.Add("maid");
            table.Columns.Add("addr");
            for (int i = 0; i < addrlist.Count; i++)
            {
                table.Rows.Add(addrlist[i].ma_id, addrlist[i].ma_address);
            }
            lvaddr.DataSource = table;
            lvaddr.DataBind();
        }
    }
}